package com.theanh.RssActivity;

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import android.content.Intent;
import android.database.SQLException;
import android.util.Log;

import com.theanh.RssActivity.db.DbAdapter;
import com.theanh.RssActivity.entity.Category;
import com.theanh.RssActivity.ui.ListCategoryScreen;
import com.theanh.RssActivity.ui.ListChannelScreen;
import com.theanh.RssActivity.ui.ListItemScreen;
import com.theanh.RssActivity.util.RssUtils;

public final class MainController {
	public static final String TAG = "MainController";
	
	
//	public static void showListCategoryScreen() {
//		Intent intent = new Intent(Store.context, ListCategoryScreen.class)
//				.setAction(Intent.ACTION_VIEW).addCategory(
//						Intent.CATEGORY_DEFAULT);
//		Store.context.startActivity(intent);
//	}

	public static void showListChannelScreen(Category category) {
		Store.categoryModelSelected.category = category;
		Intent intent = new Intent(Store.context, ListChannelScreen.class)
				.setAction(Intent.ACTION_VIEW).addCategory(
						Intent.CATEGORY_DEFAULT);
		Store.context.startActivity(intent);
	}

	public static void showListItemScreen(
			com.theanh.RssActivity.entity.Channel channel) {
		Store.channelModelSelected.channel = channel;
		Intent intent = new Intent(Store.context, ListItemScreen.class)
				.setAction(Intent.ACTION_VIEW).addCategory(
						Intent.CATEGORY_DEFAULT);
		Store.context.startActivity(intent);
	}

//	public static void updateChannel(com.theanh.RssActivity.entity.Channel channel) {
//		if (channel == null)
//			return;
//		
//		try {
//			RssUtils.fillChannel(channel);
//		} catch (Exception e) {
//			Log.e(TAG, e.toString());
//		}
//		
//		
//		if (channel == null || channel.getItems() == null
//				|| channel.getItems().size() == 0)
//			return;
//		DbAdapter dbAdapter = Store.dbAdapter;
//		long count = 0;
//		try {
//			Store.dbAdapter.open();
//
//			for (com.theanh.RssActivity.entity.Item item : channel.getItems()) {
//				Log.i(TAG, item.toString());
//				if (!item.validate()){
//					Log.i(TAG, item.getTitle() + " ::: invalidate");
//					continue;
//				}
//				
//				if (!dbAdapter.checkItemExist(item)){
//					count += dbAdapter.insertItem(item);
//					Log.i(TAG,String.valueOf(count));
//				}
//			}
//		} catch (SQLException ex) {
//			Log.e(TAG, ex.toString());
//		} finally {
//			try {
//				Store.dbAdapter.close();
//			} catch (SQLException ex) {
//				Log.e(TAG, ex.toString());
//			}
//		}
//	}

}
